<template>
  <div id="safe-echart4" style="height: 100%"></div>
</template>
<script>
export default {
  data() {
    return {
      dataList: [],
    };
  },
  mounted() {
    this.getData();
  },
  created() {},
  methods: {
    // 街道企业分布情况
    getData() {
      this.$get("/safetyproduction/getStreet").then((res) => {
        this.dataList = res.data;
        this.renderEcharts();
      });
    },
    // 渲染折线图
    renderEcharts() {
      let myChart = this.$echarts.init(document.getElementById("safe-echart4"));
      let xaxisData = this.dataList.map((v) => v.name)
      let yaxisData = this.dataList.map((v) => v.value)
      let option = {
        color: [ "#63caff" ],
        grid: {
          containLabel: true,
          left: "3%",
          right: "3%",
          bottom: "5%",
          top: "10%",
        },
        xAxis: {
          axisLabel: {
            color: "#fff",
            fontSize: 14,
            interval: 0,
            rotate: 30 // 值>0向右倾斜，值<0则向左倾斜
          },
          axisTick: {
            lineStyle: {
              color: "#384267",
            },
            show: true,
          },
          splitLine: {
            show: false,
          },
          axisLine: {
            lineStyle: {
              color: "#384267",
              width: 1,
              type: "dashed",
            },
            show: true,
          },
          data: xaxisData,
          type: "category",
        },
        yAxis: {
          axisLabel: {
            color: "#c0c3cd",
            fontSize: 14,
          },
          axisTick: {
            lineStyle: {
              color: "#384267",
              width: 1,
            },
            show: true,
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: "#384267",
              type: "dashed",
            },
          },
          axisLine: {
            lineStyle: {
              color: "#384267",
              width: 1,
              type: "dashed",
            },
            show: true,
          },
          name: "",
        },
        series: [
          {
            data: yaxisData,
            type: "bar",
            barMaxWidth: "auto",
            barWidth: 30,
            itemStyle: {
              color: {
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                type: "linear",
                global: false,
                colorStops: [
                  {
                    offset: 0,
                    color: "#0b9eff",
                  },
                  {
                    offset: 1,
                    color: "#63caff",
                  },
                ],
              },
            },
            label: {
              show: true,
              position: "top",
              distance: 10,
              color: "#fff",
            },
          },
          {
            data: [1, 1, 1, 1, 1, 1, 1, 1],
            type: "pictorialBar",
            barMaxWidth: "20",
            symbol: "diamond",
            symbolOffset: [0, "50%"],
            symbolSize: [30, 15],
          },
          {
            data: yaxisData,
            type: "pictorialBar",
            barMaxWidth: "20",
            symbolPosition: "end",
            symbol: "diamond",
            symbolOffset: [0, "-50%"],
            symbolSize: [30, 12],
            zlevel: 2,
          },
          // {
          //   data: [10, 10, 10, 10, 10, 10, 10, 10],
          //   type: "bar",
          //   barMaxWidth: "auto",
          //   barWidth: 30,
          //   barGap: "-100%",
          //   zlevel: -1,
          // },
          // {
          //   data: [1, 1, 1, 1, 1, 1, 1, 1],
          //   type: "pictorialBar",
          //   barMaxWidth: "20",
          //   symbol: "diamond",
          //   symbolOffset: [0, "50%"],
          //   symbolSize: [30, 15],
          //   zlevel: -2,
          // },
          // {
          //   data: [10, 10, 10, 10, 10, 10, 10, 10],
          //   type: "pictorialBar",
          //   barMaxWidth: "20",
          //   symbolPosition: "end",
          //   symbol: "diamond",
          //   symbolOffset: [0, "-50%"],
          //   symbolSize: [30, 12],
          //   zlevel: -1,
          // },
        ],
        tooltip: {
          trigger: "axis",
          show: false,
        },
      };

      myChart.setOption(option);
    },
  },
};
</script>
